
function insertTable11(tx,json){
    // 权限(员工)表
    var authorityArr = json.authoritys;
    if (authorityArr != null) {
        for (var i=0; i<authorityArr.length; i++) {
            insertAuthority(authorityArr[i], tx);
        }
    }

    // 员工岗位表
    var employeePositionArr = json.employeePositions;
    if (employeePositionArr != null) {
        for (var i=0; i<employeePositionArr.length; i++) {
            insertEmployeePosition(employeePositionArr[i], tx);
        }
    }

    // 职位-权限关联表
    var positionAuthorityArr = json.positionAuthoritys;
    if (positionAuthorityArr != null) {
        for (var i=0; i<positionAuthorityArr.length; i++) {
            insertPositionAuthority(positionAuthorityArr[i], tx);
        }
    }

    // 员工信息表
    var employeeArr = json.employeeInfos;
    if (employeeArr != null) {
        for (var i=0; i<employeeArr.length; i++) {
            insertEmployee(employeeArr[i], tx);
        }
    }

    // 职位薪资设置表
    var salarySettingArr = json.salarySettings;
    if (salarySettingArr != null) {
        for (var i=0; i<salarySettingArr.length; i++) {
            insertSalarySetting(salarySettingArr[i], tx);
        }
    }
}
function insertTable12(tx,json){
    // 提成方式设置表
    var deductSetting = json.deductSetting;
    insertDeductSetting(deductSetting, tx);

    // 提成方式1设定表
    var deductType1SettingArr = json.deductType1Settings;
    if (deductType1SettingArr != null) {
        for (var i=0; i<deductType1SettingArr.length; i++) {
            insertDeductType1Setting(deductType1SettingArr[i], tx);
        }
    }

    // 提成方式2设定表
    var deductType2SettingArr = json.deductType2Settings;
    if (deductType2SettingArr != null) {
        for (var i=0; i<deductType2SettingArr.length; i++) {
            insertDeductType2Setting(deductType2SettingArr[i], tx);
        }
    }

    // 提成方式3设定表
    var deductType3SettingArr = json.deductType3Settings;
    if (deductType3SettingArr != null) {
        for (var i=0; i<deductType3SettingArr.length; i++) {
            insertDeductType3Setting(deductType3SettingArr[i], tx);
        }
    }

    // 员工薪资记录表
    var salaryRecordArr = json.salaryRecords;
    if (salaryRecordArr != null) {
        for (var i=0; i<salaryRecordArr.length; i++) {
            insertSalaryRecord(salaryRecordArr[i], tx);
        }
    }
}
function insertTable13(tx,json){
    // 员工请假记录表
    var leaveArr = json.leaves;
    if (leaveArr != null) {
        for (var i=0; i<leaveArr.length; i++) {
            insertLeave(leaveArr[i], tx);
        }
    }
}

// 同步(员工考勤模块)
function leaveSync(tx, json, syncId)
{
	// 员工请假记录表
	var leaveArr = json.leaves;
	if (leaveArr != null) {
	    for (var i=0; i<leaveArr.length; i++) {
	    	insertLeave(leaveArr[i], tx);
	    }
	}
	// 同步信息表
	updateSyncinfo(tx, syncId, json.syncanchor);
}

//同步(员工提成模块)
function deductSync(tx, json, syncId)
{
	// 提成方式设置表
	var deductSetting = json.deductSetting;
	insertDeductSetting(deductSetting, tx);

	// 提成方式1设定表 
    var deductType1SettingArr = json.deductType1Settings;
    if (deductType1SettingArr != null) {
    	for (var i=0; i<deductType1SettingArr.length; i++) {
        	insertDeductType1Setting(deductType1SettingArr[i], tx);
        }
    }

	// 提成方式2设定表
    var deductType2SettingArr = json.deductType2Settings;
    if (deductType2SettingArr != null) {
    	for (var i=0; i<deductType2SettingArr.length; i++) {
        	insertDeductType2Setting(deductType2SettingArr[i], tx);
        }
    }

	// 提成方式3设定表
    var deductType3SettingArr = json.deductType3Settings;
    if (deductType3SettingArr != null) {
    	for (var i=0; i<deductType3SettingArr.length; i++) {
        	insertDeductType3Setting(deductType3SettingArr[i], tx);
        }
    }
	
	// 员工薪资记录表
    var salaryRecordArr = json.salaryRecords;
    if (salaryRecordArr != null) {
    	for (var i=0; i<salaryRecordArr.length; i++) {
        	insertSalaryRecord(salaryRecordArr[i], tx);
        }
    }
    
    // 同步信息表
	updateSyncinfo(tx, syncId, json.syncanchor);
}

//同步(员工模块)
function employeeSync(tx, json, syncId)
{
	// 权限(员工)表
    var authorityArr = json.authoritys;
    if (authorityArr != null) {
    	for (var i=0; i<authorityArr.length; i++) {
    		insertAuthority(authorityArr[i], tx);
        }
    }
	
	// 员工岗位表
    var employeePositionArr = json.employeePositions;
    if (employeePositionArr != null) {
    	for (var i=0; i<employeePositionArr.length; i++) {
    		insertEmployeePosition(employeePositionArr[i], tx);
        }
    }

	// 职位-权限关联表 
    var positionAuthorityArr = json.positionAuthoritys;
    if (positionAuthorityArr != null) {
    	for (var i=0; i<positionAuthorityArr.length; i++) {
    		insertPositionAuthority(positionAuthorityArr[i], tx);
        }
    }
    
	// 员工信息表
    var employeeArr = json.employeeInfos;
    if (employeeArr != null) {
    	for (var i=0; i<employeeArr.length; i++) {
    		insertEmployee(employeeArr[i], tx);
        }
    }
	
	// 职位薪资设置表
    var salarySettingArr = json.salarySettings;
    if (salarySettingArr != null) {
    	for (var i=0; i<salarySettingArr.length; i++) {
    		insertSalarySetting(salarySettingArr[i], tx);
        }
    }
    
    // 同步信息表
	updateSyncinfo(tx, syncId, json.syncanchor);
}

//员工请假记录表
function insertLeave(leave, tx)
{
	if (leave != null) {
		// 检索是否存在该条数据
        tx.executeSql(
            "SELECT id FROM t_leave WHERE id=" + leave.id,
            [],
            function (tx, result) {
                var len=result.rows.length;
                if (len > 0) {
                    // 存在的情况，更新数据
                	var updateSql = "update t_leave set shop_id=" +leave.shopId + ",employee_number='" + leave.employeeNumber + "',employee_name='" + leave.employeeName + 
	                    "',start_time='" + leave.startTime.replace("+"," ") + "',end_time='" + leave.endTime.replace("+"," ") +
	                    "',update_time=" + leave.updateTime + ",del_status=" + getDelStatus(leave.delStatus) + ",remark='" + leave.remark.replace(/\+/g, " ").replace(/\'/g,"&apos;").replace(/\"/g,"&quot;") + "' where id= " + leave.id;
	                tx.executeSql(updateSql);
                 } else {
                	// 不存在的情况添加数据
                 	var insertSql = "INSERT INTO t_leave(id, shop_id, employee_number, employee_name, start_time, end_time, remark, update_time, del_status) " +
             	    "VALUES (" + leave.id + "," + leave.shopId + ", '" + leave.employeeNumber + "', '" + leave.employeeName +
             	    "', '" + leave.startTime.replace("+"," ") + "', '" + leave.endTime.replace("+"," ") + "', '" + leave.remark.replace(/\+/g, " ").replace(/\'/g,"&apos;").replace(/\"/g,"&quot;") + "', " + leave.updateTime + ", " + getDelStatus(leave.delStatus) + ")";
             		tx.executeSql(insertSql);
                 }
            });
    }
}

// 提成方式设置表
function insertDeductSetting(deductSetting, tx)
{
	if (deductSetting != null) {
		// 检索是否存在该条数据
        tx.executeSql(
            "SELECT id FROM t_deduct_setting WHERE id=" + deductSetting.id,
            [],
            function (tx, result) {
                var len=result.rows.length;
                if (len > 0) {
                    // 存在的情况，更新数据
                	var updateSql = "update t_deduct_setting set shop_id=" +deductSetting.shopId + ",service_deduct_type = " + deductSetting.serviceDeductType + 
                		",recharge_deduct_type = " + deductSetting.rechargeDeductType+ ",sales_deduct_type = " + deductSetting.salesDeductType + 
                		",update_time=" + deductSetting.updateTime + ",del_status=" + getDelStatus(deductSetting.delStatus) + " where id= " + deductSetting.id;
                    tx.executeSql(updateSql);
                 } else {
                	// 不存在的情况添加数据
                	var insertSql = "INSERT INTO t_deduct_setting(id, shop_id, service_deduct_type, recharge_deduct_type, sales_deduct_type, update_time, del_status)";
                 	insertSql += " VALUES (" + deductSetting.id + "," + deductSetting.shopId + ", " + deductSetting.serviceDeductType + ", " + deductSetting.rechargeDeductType + ", " + deductSetting.salesDeductType + "," + deductSetting.updateTime + ", " + getDelStatus(deductSetting.delStatus) + ")";
                    tx.executeSql(insertSql);
                 }
            });
    }
}

// 提成方式1设定表
function insertDeductType1Setting(deductType1Setting, tx)
{
	if (deductType1Setting != null) {
		// 检索是否存在该条数据
        tx.executeSql(
            "SELECT id FROM t_deduct_type1_setting WHERE id=" + deductType1Setting.id,
            [],
            function (tx, result) {
                var len=result.rows.length;
                // 物理删除
                if (len > 1) {
                	tx.executeSql("delete FROM t_deduct_type1_setting WHERE del_status=1 AND id=" + deductType1Setting.id);  	
                }
                if (len > 0) {
                    // 存在的情况，更新数据
                	var updateSql = "update t_deduct_type1_setting set shop_id=" +deductType1Setting.shopId + ",setting_for=" + deductType1Setting.settingFor + ",position_number='" + deductType1Setting.positionNumber + "', object_id=" + deductType1Setting.objectId +
	                    ",first_type=" + deductType1Setting.firstType + ",appointed_first_rate=" + deductType1Setting.appointedFirstRate + ",inturn_first_rate=" + deductType1Setting.inturnFirstRate +
	                    ",second_type=" + deductType1Setting.secondType + ",appointed_second_rate=" + deductType1Setting.appointedSecondRate + ",inturn_second_rate=" + deductType1Setting.inturnSecondRate +
	                    ",third_type=" + deductType1Setting.thirdType + ",appointed_third_rate=" + deductType1Setting.appointedThirdRate + ",inturn_third_rate=" + deductType1Setting.inturnThirdRate +
	                    ",update_time=" + deductType1Setting.updateTime + ",del_status=" + getDelStatus(deductType1Setting.delStatus) + " where id= " + deductType1Setting.id;
	                tx.executeSql(updateSql);
                 } else {
                	// 不存在的情况添加数据
                	 var insertSql = "INSERT INTO t_deduct_type1_setting(id, shop_id, setting_for, position_number, object_id, first_type, appointed_first_rate, inturn_first_rate," +
	         	        "second_type, appointed_second_rate, inturn_second_rate, third_type, appointed_third_rate, inturn_third_rate, update_time, del_status) " +
	         	        "VALUES (" + deductType1Setting.id + "," + deductType1Setting.shopId + ","+deductType1Setting.settingFor+",'" + deductType1Setting.positionNumber + "'," + 
	         	        deductType1Setting.objectId + "," + deductType1Setting.firstType + "," + deductType1Setting.appointedFirstRate + "," + deductType1Setting.inturnFirstRate + "," + 
	         	        deductType1Setting.secondType + "," + deductType1Setting.appointedSecondRate + "," + deductType1Setting.inturnSecondRate + "," + 
	         	        deductType1Setting.thirdType + "," + deductType1Setting.appointedThirdRate + "," + deductType1Setting.inturnThirdRate + "," + deductType1Setting.updateTime + ", " + getDelStatus(deductType1Setting.delStatus) + ")";
	         	    tx.executeSql(insertSql);
                 }
            });
    }
}

// 提成方式2设定表
function insertDeductType2Setting(deductType2Setting, tx)
{
	if (deductType2Setting != null) {
		// 检索是否存在该条数据
        tx.executeSql(
            "SELECT id FROM t_deduct_type2_setting WHERE id=" + deductType2Setting.id,
            [],
            function (tx, result) {
                var len=result.rows.length;
                // 物理删除
                if (len > 1) {
                	tx.executeSql("delete FROM t_deduct_type2_setting WHERE del_status=1 AND id=" + deductType2Setting.id);  	
                }
                
                if (len > 0) {
                    // 存在的情况，更新数据
                	var updateSql = "update t_deduct_type2_setting set shop_id=" +deductType2Setting.shopId + ",setting_for=" + deductType2Setting.settingFor + 
                	    ",object_id=" + deductType2Setting.objectId + ",lower_value=" + deductType2Setting.lowerValue + ",upper_value="+ deductType2Setting.upperValue +
	                    ",first_deduct_rate=" + deductType2Setting.firstDeductRate + ",first_calculate_type=" + deductType2Setting.firstCalculateType +
	                    ",second_deduct_rate=" + deductType2Setting.secondDeductRate + ",second_calculate_type=" + deductType2Setting.secondCalculateType +
	                    ",third_deduct_rate=" + deductType2Setting.thirdDeductRate + ",third_calculate_type=" + deductType2Setting.thirdCalculateType +
	                    ",update_time=" + deductType2Setting.updateTime + ",del_status=" + getDelStatus(deductType2Setting.delStatus) + " where id= " + deductType2Setting.id;
	                tx.executeSql(updateSql);
                 } else {
                	// 不存在的情况添加数据
                	 var insertSql = "INSERT INTO t_deduct_type2_setting(id,shop_id,setting_for,object_id,lower_value,upper_value,first_deduct_rate,first_calculate_type," +
	         	        "second_deduct_rate,second_calculate_type,third_deduct_rate,third_calculate_type,update_time,del_status) " +
	         	        "VALUES (" + deductType2Setting.id + "," + deductType2Setting.shopId + ","+deductType2Setting.settingFor+","+deductType2Setting.objectId+"," + deductType2Setting.lowerValue + "," + deductType2Setting.upperValue + "," + 
	         	        deductType2Setting.firstDeductRate + "," + deductType2Setting.firstCalculateType + "," + deductType2Setting.secondDeductRate + "," + deductType2Setting.secondCalculateType + ","+ 
	         	        deductType2Setting.thirdDeductRate + "," + deductType2Setting.thirdCalculateType + "," + deductType2Setting.updateTime + ", " + getDelStatus(deductType2Setting.delStatus) + ")";
	         	    tx.executeSql(insertSql);
                 }
            });
    }
}

// 提成方式3设定表
function insertDeductType3Setting(deductType3Setting, tx)
{
	if (deductType3Setting != null) {
		// 检索是否存在该条数据
        tx.executeSql(
            "SELECT id FROM t_deduct_type3_setting WHERE id=" + deductType3Setting.id,
            [],
            function (tx, result) {
                var len=result.rows.length;
                // 物理删除
                if (len > 1) {
                	tx.executeSql("delete FROM t_deduct_type3_setting WHERE del_status=1 AND id=" + deductType3Setting.id);  	
                }
                
                if (len > 0) {
                    // 存在的情况，更新数据
                	var updateSql = "update t_deduct_type3_setting set shop_id=" +deductType3Setting.shopId + ",setting_for=" + deductType3Setting.settingFor + ",object_id=" + deductType3Setting.objectId +
	                    ",first_calculate_type=" + deductType3Setting.firstCalculateType + ",first_deduct_rate=" + deductType3Setting.firstDeductRate + ",first_inturn_rate=" + deductType3Setting.firstInturnRate +
	                    ",second_calculate_type=" + deductType3Setting.secondCalculateType + ",second_deduct_rate=" + deductType3Setting.secondDeductRate + ",second_inturn_rate=" + deductType3Setting.secondInturnRate +
	                    ",third_calculate_type=" + deductType3Setting.thirdCalculateType + ",third_deduct_rate=" + deductType3Setting.thirdDeductRate + ",third_inturn_rate=" + deductType3Setting.thirdInturnRate +
	                    ",update_time=" + deductType3Setting.updateTime + ",del_status=" + getDelStatus(deductType3Setting.delStatus) + " where id= " + deductType3Setting.id;
	                tx.executeSql(updateSql);
                 } else {
                	// 不存在的情况添加数据
                	var insertSql = "INSERT INTO t_deduct_type3_setting(id, shop_id, setting_for, object_id, first_calculate_type, first_deduct_rate, first_inturn_rate," +
	         	        "second_calculate_type, second_deduct_rate, second_inturn_rate, third_calculate_type, third_deduct_rate, third_inturn_rate, update_time, del_status) " +
	         	        "VALUES (" + deductType3Setting.id + "," + deductType3Setting.shopId + ","+deductType3Setting.settingFor+"," + deductType3Setting.objectId + "," + 
	         	        deductType3Setting.firstCalculateType + "," + deductType3Setting.firstDeductRate + "," + deductType3Setting.firstInturnRate + "," + 
	         	        deductType3Setting.secondCalculateType + "," + deductType3Setting.secondDeductRate + "," + deductType3Setting.secondInturnRate + "," + 
	         	        deductType3Setting.thirdCalculateType + "," + deductType3Setting.thirdDeductRate + "," + deductType3Setting.thirdInturnRate + "," + 
	         	        deductType3Setting.updateTime + ", " + getDelStatus(deductType3Setting.delStatus) + ")";
	         	    tx.executeSql(insertSql);
                 }
            });
    }
}

// 员工薪资记录表
function insertSalaryRecord(salaryRecord, tx)
{
	if (salaryRecord != null) {
		// 检索是否存在该条数据
        tx.executeSql(
            "SELECT id FROM t_salary_record WHERE id=" + salaryRecord.id,
            [],
            function (tx, result) {
                var len=result.rows.length;
                if (len > 0) {
                    // 存在的情况，更新数据
                	var saveSql = "update t_salary_record set shop_id=" +salaryRecord.shopId + ",employee_id=" + salaryRecord.employeeId + 
                	    ",employee_name='" + salaryRecord.employeeName + "',base_salary=" + salaryRecord.baseSalary + ",card_sale_bonus=" + salaryRecord.cardSalebBonus + 
	                	",service_bonus=" + salaryRecord.serviceBonus + ",product_bonus=" + salaryRecord.productBonus + ",subsidy=" + salaryRecord.subsidy + 
	                	",reward=" + salaryRecord.reward + ",daily_reward=" + salaryRecord.dailyReward + ",deduct_value=" + salaryRecord.deductValue + 
	                	",endowment_insurance=" + salaryRecord.endowmentInsurance + ",public_accumulation_funds=" + salaryRecord.publicAccumulationFunds +
	                	",gross_salary=" + salaryRecord.grossSalary + ",income_tax=" + salaryRecord.incomeTax + ",net_salary=" + salaryRecord.netSalary + 
	                	",provide_status=" + salaryRecord.provideStatus + ",remark='" + salaryRecord.remark.replace(/\+/g, " ").replace(/\'/g,"&apos;").replace(/\"/g,"&quot;") + "',salary_date='" + salaryRecord.salaryDate +
	                	"',update_time=" + salaryRecord.updateTime + ",del_status=" + getDelStatus(salaryRecord.delStatus) + " where id= " + salaryRecord.id;
	                tx.executeSql(saveSql);
                 } else {
                	// 不存在的情况添加数据
                	var insertSql = "INSERT INTO t_salary_record";
	         	    	insertSql += "(id,shop_id,employee_id,employee_name,base_salary,card_sale_bonus,service_bonus,product_bonus,subsidy,reward,daily_reward,deduct_value,";
	         	    	insertSql += "endowment_insurance,public_accumulation_funds,gross_salary,income_tax,net_salary,provide_status,remark,salary_date,update_time, del_status)";
	         	    	insertSql += "VALUES";
	         	    	insertSql += "("+salaryRecord.id+","+salaryRecord.shopId+","+salaryRecord.employeeId+",'"+salaryRecord.employeeName+"',"+salaryRecord.baseSalary+","+salaryRecord.cardSalebBonus;
	         	    	insertSql += ","+salaryRecord.serviceBonus+","+salaryRecord.productBonus+","+salaryRecord.subsidy+","+salaryRecord.reward+","+salaryRecord.dailyReward+","+salaryRecord.deductValue;
	         	    	insertSql += ","+salaryRecord.endowmentInsurance+","+salaryRecord.publicAccumulationFunds+","+salaryRecord.grossSalary+","+salaryRecord.incomeTax+","+salaryRecord.netSalary;
	         	    	insertSql += ","+salaryRecord.provideStatus+",'"+salaryRecord.remark.replace(/\+/g, " ").replace(/\'/g,"&apos;").replace(/\"/g,"&quot;")+"','"+salaryRecord.salaryDate+"',"+salaryRecord.updateTime+","+getDelStatus(salaryRecord.delStatus)+")";
	         	    tx.executeSql(insertSql);
                 }
            });
    }
}

// 权限(员工)表
function insertAuthority(authority, tx)
{
	if (authority != null) {
		// 检索是否存在该条数据
        tx.executeSql(
            "SELECT id FROM t_authority_e WHERE id=" + authority.id,
            [],
            function (tx, result) {
                var len=result.rows.length;
                if (len > 0) {
                    // 存在的情况，更新数据
                	var updateSql = "update t_authority_e set shop_id=" +authority.shopId + ",module_name=" + authority.moduleName + ",setting=" + authority.setting +
	                    ",update_time=" + authority.updateTime + ",del_status=" + getDelStatus(authority.delStatus) + " where id= " + authority.id;
	                tx.executeSql(updateSql);
                 } else {
                	// 不存在的情况添加数据
                 	var insertSql = "INSERT INTO t_authority_e(id, shop_id, module_name, setting, update_time, del_status) ";
                 	insertSql += "VALUES ("+authority.id+"," + authority.shopId + "," + authority.moduleName + "," + authority.setting + "," +authority.updateTime+","+getDelStatus(authority.delStatus)+")";
                     tx.executeSql(insertSql);
                 }
            });
    }
}

// 员工岗位表
function insertEmployeePosition(employeePosition, tx)
{
	if (employeePosition != null) {
		// 检索是否存在该条数据
        tx.executeSql(
            "SELECT id FROM t_employee_position WHERE id=" + employeePosition.id,
            [],
            function (tx, result) {
                var len=result.rows.length;
                if (len > 0) {
                    // 存在的情况，更新数据
                	var updateSql = "update t_employee_position set shop_id=" +employeePosition.shopId + ",number = '" + employeePosition.number + "', position_name='"
	                + employeePosition.positionName + "', remark='" + employeePosition.remark.replace(/\+/g, " ").replace(/\'/g,"&apos;").replace(/\"/g,"&quot;")+ "',update_time=" + employeePosition.updateTime + ",del_status=" + getDelStatus(employeePosition.delStatus) + " where id= "+employeePosition.id;
                    tx.executeSql(updateSql);
                 } else {
                	// 不存在的情况添加数据
                 	var insertSql = "INSERT INTO t_employee_position(id, shop_id, number,position_name,remark, update_time,del_status) ";
                 	insertSql += "VALUES ("+employeePosition.id+"," + employeePosition.shopId + ",'" + employeePosition.number + "','" + employeePosition.positionName + "','" + employeePosition.remark.replace(/\+/g, " ").replace(/\'/g,"&apos;").replace(/\"/g,"&quot;") + "'," +employeePosition.updateTime+","+getDelStatus(employeePosition.delStatus)+")";
                     tx.executeSql(insertSql);
                 }
            });
    }
}

// 职位-权限关联表
function insertPositionAuthority(positionAuthority, tx)
{
	if (positionAuthority != null) {
		// 检索是否存在该条数据
        tx.executeSql(
            "SELECT id FROM t_position_authority WHERE id=" + positionAuthority.id,
            [],
            function (tx, result) {
                var len=result.rows.length;
                if (len > 0) {
                    // 存在的情况，更新数据
                	var updateSql = "update t_position_authority set shop_id=" +positionAuthority.shopId + ",position_id=" + positionAuthority.positionId + ", authority_e_id="
	                + positionAuthority.authorityeId + ",update_time=" + positionAuthority.updateTime + ",del_status=" + getDelStatus(positionAuthority.delStatus) + " where id= "+positionAuthority.id;
                    tx.executeSql(updateSql);
                 } else {
                	// 不存在的情况添加数据
                 	var insertSql = "INSERT INTO t_position_authority(id, shop_id, position_id,authority_e_id,update_time,del_status) ";
                 	insertSql += "VALUES ("+positionAuthority.id+"," + positionAuthority.shopId + "," + positionAuthority.positionId + "," + positionAuthority.authorityeId + ","  + positionAuthority.updateTime +","+getDelStatus(positionAuthority.delStatus)+")";
                     tx.executeSql(insertSql);
                 }
            });
    }
}

// 员工信息表
function insertEmployee(employee, tx)
{
	if (employee != null) {
		// 检索是否存在该条数据
        tx.executeSql(
            "SELECT id FROM t_employee WHERE id=" + employee.id,
            [],
            function (tx, result) {
                var len=result.rows.length;
                if (len > 0) {
                    // 存在的情况，更新数据
                	var updateSql = "update t_employee set shop_id=" +employee.shopId + ",number = '" + employee.number + "', name= '"+ employee.name + "', position_id="
		                + employee.positionId + ", linked_id=" + employee.linkedId + ", gender=" + employee.gender +  ", birthday='" + employee.birthday.replace("+"," ") +  "', education='"
		                + employee.education + "', entry_time='" + employee.entryTime.replace("+"," ") +  "', cellphone='" + employee.cellphone
		                + "', identity_card='" + employee.identityCard + "', address='" + employee.address +"',update_time=" + employee.updateTime
		                + ",del_status=" + getDelStatus(employee.delStatus) + " where id= "+ employee.id;
                    tx.executeSql(updateSql);
                 } else {
                	// 不存在的情况添加数据
                 	var insertSql = "INSERT INTO t_employee(id, number, shop_id,name,position_id,linked_id,gender,birthday,education,entry_time,cellphone,identity_card,address, update_time,del_status) ";
                 	insertSql += "VALUES ("+employee.id+",'" + employee.number + "'," + employee.shopId + ",'"  + employee.name + "'," + employee.positionId + ",";
                 	insertSql += employee.linkedId+ "," + employee.gender + ",'"  + employee.birthday.replace("+"," ") + "','" + employee.education + "','"  + employee.entryTime.replace("+"," ") + "','";
                 	insertSql += employee.cellphone + "','" + employee.identityCard + "','" + employee.address + "'," + employee.updateTime +","+getDelStatus(employee.delStatus)+")";
                     tx.executeSql(insertSql);
                 }
            });
    }
}

// 职位薪资设置表
function insertSalarySetting(salarySetting, tx)
{
	if (salarySetting != null) {
		// 检索是否存在该条数据
        tx.executeSql(
            "SELECT id FROM t_salary_setting WHERE id=" + salarySetting.id,
            [],
            function (tx, result) {
                var len=result.rows.length;
                if (len > 0) {
                    // 存在的情况，更新数据
                	var updateSql = "update t_salary_setting set shop_id="+salarySetting.shopId+",position_number='"+salarySetting.positionNumber;
                	updateSql += "',position_name='"+salarySetting.positionName+"',base_salary="+salarySetting.baseSalary+",base_salary_mode="+salarySetting.baseSalaryMode+",card_sale_bonus="+salarySetting.cardSaleBonus;
                	updateSql += ",service_bonus="+salarySetting.serviceBonus+",product_bonus="+salarySetting.productBonus+",subsidy="+salarySetting.subsidy+",subsidy_mode="+salarySetting.subsidyMode;
                	updateSql += ",reward="+salarySetting.reward+",daily_reward="+salarySetting.dailyReward+",deduct_value="+salarySetting.deductValue+",public_accumulation_funds="+salarySetting.publicAccumulationFunds;
                	updateSql += ",endowment_insurance="+salarySetting.endowmentInsurance+",income_tax="+salarySetting.incomeTax;
                	updateSql += ",update_time=" + salarySetting.updateTime + ",del_status=" + getDelStatus(salarySetting.delStatus) +" where id="+salarySetting.id;
	            	tx.executeSql(updateSql);
                 } else {
                	// 不存在的情况添加数据
                 	var insertSql = "INSERT INTO t_salary_setting(id,shop_id,position_number,position_name,base_salary,base_salary_mode,card_sale_bonus,";
                 	insertSql += "service_bonus,product_bonus,subsidy,subsidy_mode,reward,daily_reward,deduct_value,public_accumulation_funds,endowment_insurance,";
                 	insertSql += "income_tax,update_time,del_status)";
                 	insertSql += "VALUES("+salarySetting.id+","+salarySetting.shopId+",'"+salarySetting.positionNumber+"','"+salarySetting.positionName+"',"+salarySetting.baseSalary+","+salarySetting.baseSalaryMode+","+salarySetting.cardSaleBonus;
                 	insertSql += ","+salarySetting.serviceBonus+","+salarySetting.productBonus+","+salarySetting.subsidy+","+salarySetting.subsidyMode+","+salarySetting.reward+","+salarySetting.dailyReward+","+salarySetting.deductValue;
                 	insertSql += ","+salarySetting.publicAccumulationFunds+","+salarySetting.endowmentInsurance+","+salarySetting.incomeTax+","+salarySetting.updateTime +","+getDelStatus(salarySetting.delStatus)+")";
                 	tx.executeSql(insertSql);
                 }
            });
    }
}

//同步信息表
function updateSyncinfo(tx, syncId, syncanchor)
{
	var updateSql = "update t_syncinfo set update_time=" + syncanchor + " where id= " + syncId;
    tx.executeSql(updateSql);
}

function getDelStatus(delStatus)
{
    if (delStatus == true ) {
    	return 1;
    } else {
    	return 0;
    }
}

function isEmpty(number)
{
    if (number == null || number.length == 0) {
    	return 0;
    }
    return number;
}